/****************************************************************************
 * Copyright (C) 2012
 * by Dj_Skual
 *
 * This software is provided 'as-is', without any express or implied
 * warranty. In no event will the authors be held liable for any
 * damages arising from the use of this software.
 *
 * Permission is granted to anyone to use this software for any
 * purpose, including commercial applications, and to alter it and
 * redistribute it freely, subject to the following restrictions:
 *
 * 1. The origin of this software must not be misrepresented; you
 * must not claim that you wrote the original software. If you use
 * this software in a product, an acknowledgment in the product
 * documentation would be appreciated but is not required.
 *
 * 2. Altered source versions must be plainly marked as such, and
 * must not be misrepresented as being the original software.
 *
 * 3. This notice may not be removed or altered from any source
 * distribution.
 *
 * gui_banner.h
 *
 * for SaveGame Manager GX 2012
 ***************************************************************************/
#ifndef _GUI_BANNER_H_
#define _GUI_BANNER_H_

#include "gui.h"
#include "../ImageOperations/TplFile.h"
#include "../ImageOperations/Texture.h"

#define MAXFRAMES 8

class GuiSaveBanner : public GuiImage
{
public:
	//!Constructor
	//!\ create a TPL of the banner of a "banner.bin"
	//!\ this function expects a buffer containing the entire banner.bin and it takes care of getting the data out of it
	//!\ and adding the propper TPL header
	GuiSaveBanner(ByteArray &mem);
	GuiSaveBanner(u8 *mem);
	void Init(u8 *mem);
	
	//!Destructor
	virtual ~GuiSaveBanner();
	
	void Draw();
	
protected:
	bool filecheck;
	int tplfilesize;
	TplFile * tplFile;
	Texture * texture;
};

class GuiSaveIcon  : public GuiImage
{
public:
	//!Constructor
	//! create the icon from the memory buffer filled with a full banner.bin
	//! mem is the buffer containing the banner.bin
	//! len is the size of the buffer
	GuiSaveIcon(ByteArray &mem);
	GuiSaveIcon(u8 *mem, u32 len);
	void Init(u8 *mem, u32 len);
	
	//!Destructor
	virtual ~GuiSaveIcon();

	//!Get the number of frames making up this icon
	//!Everything after and including the first empty image is dropped and not counted or used
	u8 GetFrameCnt() { return frameCnt; }

	//!Get the currently displayed frame
	u8 GetFrame() { return currentFrame; }

	//!Set the icon to a certain frame
	void SetFrame(int i) { currentFrame = i; }

	//!Check if this has at least one frame to display
	bool IsValid() { return filecheck; }

	//!Change the size of the banner
	//!This function just stretches the texture to fill a rectangle with the size, so it loses detail when you go too big.
	void SetSize(int w, int h) { width = w; height = h; }
	
	//!Draw the current frame.
	//!This function also keeps count and is responsible for triggering the advance to the next frame.
	void Draw();
	
protected:
	//!Move to the next frame
	void AdvanceFrame();

	TplFile * tplFile[MAXFRAMES];
	Texture * texture[MAXFRAMES];
	bool filecheck;
	bool reverseAnim;
	int flags;
	u16 animSpeed;
	u8 frameCnt;
	u8 currentFrame;
	u8 counter;
};

/*class GuiGCBanner : public GuiImage
{
public:
	//!Constructor
	//!\param mem Memory of the loaded tpl
	//!\param len Filesize of the tpl
	//!\param fmt Format of the tpl
	//!\param w Width of the tpl
	//!\param h Height of the tpl
	GuiGCBanner(u8 *mem,
				u32 banner_offset,
				u8 fmt,
				int w = CARD_BANNER_W,
				int h = CARD_BANNER_H);
	
	//!Destructor
	virtual ~GuiGCBanner();
	
	void Draw();
	
protected:
	TplFile * tplFile;
	Texture * texture;
	bool filecheck;
	u8 format;
	int tplfilesize;
};*/

class GuiGCIcon  : public GuiImage
{
public:
	//!Constructor
	GuiGCIcon(u8 *mem,
			  std::vector<u32 > &offset,
			  std::vector<u32 > &offset_tlut,
			  u8 speed,
			  u8 fmt,
			  u8 anim,
			  int w = CARD_ICON_W,
			  int h = CARD_ICON_H);
	
	//!Destructor
	virtual ~GuiGCIcon();
	
	//!Get the number of frames making up this icon
	//!everything after and including the first empty image is dropped and not counted or used
	u8 GetFrameCnt() { return frameCnt; }
	
	//!Get the currently displayed frame
	u8 GetFrame() { return currentFrame; }
	
	//!Set the icon to a certain frame
	void SetFrame(int i) { currentFrame = i; }
	
	//!Check if this has at least one frame to display
	bool IsValid() { return filecheck; }
	
	//!Change the size of the banner
	//!This function just stretches the texture to fill a rectangle with the size, so it loses detail when you go too big.
	void SetSize(int w, int h) { width = w; height = h; }
	
	//!Draw the current frame.
	//!This function also keeps count and is responsible for triggering the advance to the next frame.
	void Draw();
	
protected:
	//!Move to the next frame
	void AdvanceFrame();
	
	TplFile * tplFile[CARD_MAXICONS];
	Texture * texture[CARD_MAXICONS];
	bool filecheck;
	bool reverseAnim;
	u8 tplformat;
	u8 animType;
	u8 animSpeed;
	u8 frameCnt;
	u8 currentFrame;
	u8 counter;
};

#endif
